﻿@using Telerik.Web.Mvc.UI
@using MvcFront.Models

@{
    ViewBag.Title = "title";
}
    @Html.ValidationSummary(true)
<h2>Назначенные группе формы документов</h2>

@Html.ActionLink("Назначить форму", "SelectDocTemplate")
@(Html.Telerik().Grid<GroupDocAppointmentListViewModel>()
        .Name("GroupDocAppintmentListGrid")
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_GroupDocAppointmentList", "GroupDocAppointment"))
        .ClientEvents(events => events.OnComplete("onCompleteGroupAppointment"))
                   .Columns(columns =>
                   {
                       columns.AutoGenerate(column =>
                       {
                           column.Width = "150px";
                           if (column.Member == "ID")
                               column.Visible = false;
                       });
                       columns.Command(command =>
                       {
                           command.Custom("viewDetails").Text("Информация")
                            .DataRouteValues(route => route.Add(o => o.ID).RouteKey("id"))
                            .Action("DetailsGroupDocAppointment", "GroupDocAppointment")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("EditDetails").Text("Редактировать")
                            .DataRouteValues(route => route.Add(o => o.ID).RouteKey("id"))
                            .Action("EditGroupDocAppointment", "GroupDocAppointment")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("ChangeStateDetails").Text("Выключить/Выключить")
                            .DataRouteValues(route => route.Add(o => o.ID).RouteKey("id"))
                            .Ajax(true)
                            .Action("ChangeState", "GroupDocAppointment")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("DeleteDetails").Text("Удалить")
                            .DataRouteValues(route => route.Add(o => o.ID).RouteKey("id"))
                            .Action("DeleteGroupDocAppointment", "GroupDocAppointment")
                            .HtmlAttributes(new { style = "text-align: center" });
                       }).Width(50);
                   })
                 .Sortable()
                .Pageable()

    ) 
     
<h2>Доступные для самозаполнения участникам группы формы документов</h2>

@Html.ActionLink("Добавить  форму", "SelectDocTemplateForPersonal")
@(Html.Telerik().Grid<PersonalDocTemplateListViewModel>()
        .Name("PersonalDocTemplateListGrid")
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_PersonalDocTemplateList", "GroupDocAppointment"))
                    .ClientEvents(events => events.OnComplete("onCompletePersonalDocTemplate").OnCommand("onCommandPersonalDocTemplate"))
                       .Columns(columns =>
                       {
                           columns.AutoGenerate(column =>
                           {
                               column.Width = "150px";
                               if (column.Member == "PersonalDocTemplateId")
                                   column.Visible = false;
                           });
                           columns.Command(command => command.Custom("DeleteDetails").Text("Удалить")
                                                          .DataRouteValues(route => route.Add(o => o.PersonalDocTemplateId).RouteKey("personalDocTemplateId"))
                                                          .Ajax(true)
                                                          .Action("DeletePersonalDocTemplate", "GroupDocAppointment")
                                                          .HtmlAttributes(new { style = "text-align: center" })).Width(50);
                       })
                     .Sortable()
                    .Pageable()
    )  
<script type="text/javascript">
    function onCompleteGroupAppointment(e) {
              if (e.name == "ChangeStateDetails") {
                  var grid = $('#GroupDocAppintmentListGrid').data("tGrid");
                  if (grid != null) {
                      grid.rebind();
                  }
              }
          }
          function onCompletePersonalDocTemplate(e) {
              if (e.name == "DeleteDetails") {
                  var grid = $('#PersonalDocTemplateListGrid').data("tGrid");
                  if (grid != null) {
                      grid.rebind();
                  }
              }
          }
          function onCommandPersonalDocTemplate(e) {
              if (e.name == 'DeleteDetails') {
                  if (!confirm("Вы уверены что хотите удалить возможность заполнения шаблона?")) {
                      e.preventDefault();
                  }
              }
          }
</script>